package com.eric.ztea.controller;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.eric.ztea.dao.EqPriceRepository;
import com.eric.ztea.domain.EqPrice;

@RestController
@RequestMapping("/api/eqPrice")
public class EqpriceController {

	@Autowired
	EqPriceRepository eqpriceRepository;	
	
	@GET
	@RequestMapping(value = "/findById")
	public EqPrice findById(@RequestParam(value = "id", required = true) Long id) {
		return eqpriceRepository.findById(id);
	}

	@GET
	@RequestMapping(value = "/findByEqId")
	public EqPrice findByEqId(@RequestParam(value = "eqid", required = true) Long eqid) {
		return eqpriceRepository.findByEqid(eqid);
	}
	
	@POST
	@RequestMapping(value = "/save")
	public EqPrice save(@RequestParam(value = "id", required = false) Long id,
			@RequestParam(value = "eqid", required = true) Long eqid,
			@RequestParam(value = "priceid", required = true) Long priceid) {
		return eqpriceRepository.save(new EqPrice(id, eqid, priceid));
	}
	
	@DELETE
	@RequestMapping(value = "/delete")
	public void delete(@RequestParam(value = "id", required = true) Long id)
	{
		eqpriceRepository.delete(id);
	}
	
}
